<?php
/**
 * The template for displaying all pages.
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site will use a
 * different template.
 *
 * @package WordPress
 * @subpackage Twenty_Eleven
 * @since Twenty Eleven 1.0
 */
get_header(); ?>

<div id="container-inner">
  <?php get_sidebar(); ?>

  <div id="primary">
          <div id="content" role="main">
                  <?php the_post(); ?>
            
                  <?php get_template_part( 'content', 'page' ); ?>
                  <?php
                    $metaValue = get_post_meta(get_the_ID(), 'category_name', true); 
                    
                    if(!is_null($metaValue) && $metaValue != '')
                    {
                      query_posts( 'category_name=' . $metaValue);

                      while ( have_posts() )
                      {
                        the_post();
                        get_template_part( 'content', 'index' );
                      }

                      // bardzo ważne! inaczej mogą pojawić się dziwaczne błędy związane z użyciem the_post()
                      wp_reset_query();        
                    }                    
                  ?>

          </div><!-- #content -->
  </div><!-- #primary -->
</div>
<?php get_footer(); ?>